package cn.wolfcode.car.business.web.controller.system;


import cn.wolfcode.car.base.domain.User;
import cn.wolfcode.car.base.service.IUserService;
import cn.wolfcode.car.business.domain.BusLeave;
import cn.wolfcode.car.business.mapper.BusLeaveMapper;
import cn.wolfcode.car.business.query.BusLeaveQuery;
import cn.wolfcode.car.business.service.IBusLeaveService;
import cn.wolfcode.car.business.vo.ServiceItemAuditVO;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import cn.wolfcode.car.shiro.ShiroUtils;
import org.apache.poi.util.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * 套餐审核控制器
 */
@Controller
@RequestMapping("business/busLeave")
public class BusLeaveController {
    //模板前缀
    private static final String prefix = "business/busLeave/";

    @Autowired
    private IBusLeaveService busLeaveService;

    @Autowired
    private IUserService userService;

    //页面------------------------------------------------------------
    //列表
    //@RequiresPermissions("system:busLeave:view")
    @RequestMapping("/listPage")
    public String listPage(){

        return prefix + "list";
    }

    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<BusLeave> query(BusLeaveQuery qo){
        return busLeaveService.query(qo);
    }

    @RequestMapping("/cancelApply")
    @ResponseBody
    public AjaxResult cancelApply(Long id){
        return AjaxResult.success();
    }


    @RequestMapping("/todoPage")
    public String todoPage(){
        return prefix+"todoPage";
    }
    @RequestMapping("/donePage")
    public String donePage(){
        return prefix+"donePage";
    }

    @RequestMapping("/auditPage")
    public String auditPage(Model model){

        List<User> mgrs = userService.queryByRoleKey("mgr");
        model.addAttribute("mgrs",mgrs);
        List<User> hrs = userService.queryByRoleKey("hr");
        model.addAttribute("hrs",hrs);
        return prefix+"auditPage";
    }

    @RequestMapping("/todoQuery")
    @ResponseBody
    public TablePageInfo<BusLeave> todoQuery(BusLeaveQuery qo){
        //当登录者与审核人一致时才能看到数据
        qo.setAuditId(ShiroUtils.getUserId());
        //当状态为审核中时才能查看
        return busLeaveService.query(qo);
    }
    @RequestMapping("/doneQuery")
    @ResponseBody
    public TablePageInfo<BusLeave> doneQuery(BusLeaveQuery qo){
        //因为我们审核的时候会传入备注信息，里面设置了审核人的名字，这里使用模糊查询，将当前登陆的用户传入，进行过滤
//        qo.setInfo(ShiroUtils.getUser().getUserName());
        return busLeaveService.query(qo);
    }
    @RequestMapping("/audit")
    @ResponseBody
    public AjaxResult audit(Long id,Integer auditStatus,String info){
//       busLeaveService.audit(id,auditStatus,info);
        return AjaxResult.success();
    }

    @RequestMapping("/startAudit")
    @ResponseBody
    public AjaxResult startAudit(BusLeave busLeave,Integer mgr,Integer hr){
        busLeaveService.startAudit(busLeave,mgr,hr);
        return AjaxResult.success();
    }
}
